classdef descentRate_dev < Processor_dev
  % Class for calculating descent rate ala SBE Derive, i.e., using many-
  %     point least-squares regression to estimate speed from depth
  % Derived from Processor_dev
  % Constructor signature: W = descentRate_dev(data, conn, Z), all args. optional
  %
  % Author: David Goldsmith, Wash. State Dept. of Ecology, dgol461@ecy.wa.gov
  % Release date: N/A
  
    properties
      % inherited from Processor_dev
      % inData;
      % castDT;
      % scanRate;
      % ParamID;
      % ParamDesc;
      % SBEprec;
      % EquipID;
        DBdata;
        outData;
    end
    
    methods
        function W = descentRate_dev(data, conn, Z) % Constructor
            W = W@Processor_dev(data);

            if nargin > 1, W.getDBdata(conn, 'W'); end
            if nargin==3, W.mainFormula(Z); end
        end
        
        function mainFormula(obj, Z)
          % Z = (positive) depth
            global instHeaderData

            scanRate = instHeaderData.scanRate;
            windowSize = obj.DBdata.WwindowSize;
            W = nans(size(Z));
            t = (0:(1/scanRate):windowSize)';
            a = [t ones(size(t))];
            window = numel(t);
            for n = (floor(window/2)+1) : (numel(W)-floor(window/2))
                mb = a\Z(n-floor(window/2) : n+floor(window/2));
                W(n) = mb(1);
            end
            obj.outData = W;
        end
        
        function delete(obj) % Destructor
            % Here in case I need it
        end
        
    end
    
end